package com.liyy.platform.controller;

import com.liyy.platform.domain.Goods;
import com.liyy.platform.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/search/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    //用于测试添加数据，实际数据通过rabbitMQ监听程序自动添加进ES
    @GetMapping("/saveProduct")
    public Goods saveProduct(){
        Goods goods=new Goods();
        goods.setId(100L);
        goods.setGoodsName("bijiben123");
        productService.saveProduct(goods);
        return goods;
    }

    //用于测试删除数据，实际数据通过rabbitMQ监听程序自动添加进ES
    @GetMapping("/delProduct")
    public void delProduct(long id){
        productService.deleteProduct(id);
    }

    //产品的查询及分页
    @RequestMapping("/getProductList")
    public List getProductList(String goodsName, String goodsBrand, String goodsAttr,
                               @RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize ){
        return productService.getProductList(goodsName,goodsBrand,goodsAttr,pageNo,pageSize);
    }

}
